package com.jiangyg.mall.core.enums;

import org.apache.commons.lang.StringUtils;

/**
 * 类描述：动态查询条件运算符
 * 
 * @author jiangyg
 * @date 2020-06-16
 * @version 2.0
 */
public enum Operator {

    /**
     * 等于
     */
    EQ("EQ", "="),

    /**
     * 大于
     */
    GT("GT", ">"),

    /**
     * 大于等于
     */
    GE("GE", ">="),

    /**
     * 小于
     */
    LT("LT", "<"),

    /**
     * 小于等于
     */
    LE("LE", "<="),

    /**
     * 左like
     */
    LK("LK", "like"),

    /**
     * 左右like
     */
    LL("LL", "like"),

    /**
     * 右like
     */
    RL("RL", "like"),

    /**
     * in
     */
    IN("IN", "in"),

    /**
     * between
     */
    BT("BT", "between");

    /**
     * 代码
     */
    public final String code;

    /**
     * 值
     */
    public final String value;

    Operator(String code, String value) {
        this.code = code;
        this.value = value;
    }

    /**
     * 功能描述：根据代码判断值
     * 
     * @param code 代码
     * @return Operator
     */
    public static Operator decide(String code) {
        for (Operator operator : Operator.values()) {
            if (StringUtils.equalsIgnoreCase(code, operator.code)) {
                return operator;
            }
        }
        return null;
    }

    /**
     * 功能描述：判断操作符是否范围类型
     * 
     * @param op 操作符
     * @return 返回boolean类型
     */
    public static boolean isScope(Operator op) {
        return op == Operator.IN || op == Operator.BT;
    }

    @Override
    public String toString() {
        return "Operator [code=" + this.code + ", value=" + this.value + "]";
    }

}
